<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取跟上一次语句句柄操作相关的扩展错误信息</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="pdostatement.errorcode.html">« PDOStatement::errorCode</a></li>
      <li style="float: right;"><a href="pdostatement.execute.html">PDOStatement::execute »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.pdostatement.html">PDOStatement</a></li>
    <li>获取跟上一次语句句柄操作相关的扩展错误信息</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="pdostatement.errorinfo" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDOStatement::errorInfo</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDOStatement::errorInfo</span> &mdash; <span class="dc-title">
   获取跟上一次语句句柄操作相关的扩展错误信息
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdostatement.errorinfo-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>PDOStatement::errorInfo</strong></span>(): <span class="type">array</span></div>


 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdostatement.errorinfo-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>PDOStatement::errorInfo()</strong></span> 返回一个关于上一次语句句柄执行操作的错误信息的数组 。该数组包含下列字段：
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Element</th>
       <th>Information</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>SQLSTATE 错误码（一个由5个字母或数字组成的在 ANSI SQL 标准中定义的标识符）。</td>
      </tr>

      <tr>
       <td>1</td>
       <td>具体驱动错误码。</td>
      </tr>

      <tr>
       <td>2</td>
       <td>具体驱动错误信息。</td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdostatement.errorinfo-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1065"><p><strong>示例 #1 显示连接到DB2数据库的 PDO_ODBC 连接的 errorInfo() 的字段</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;激发一个错误&nbsp;--&nbsp;&nbsp;BONES&nbsp;数据表不存在&nbsp;*/<br /></span><span style="color: #0000BB">$sth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;skull&nbsp;FROM&nbsp;bones'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br />echo&nbsp;</span><span style="color: #DD0000">"\nPDOStatement::errorInfo():\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errorInfo</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
PDOStatement::errorInfo():
Array
(
    [0] =&gt; 42S02
    [1] =&gt; -204
    [2] =&gt; [IBM][CLI Driver][DB2/LINUX] SQL0204N  &quot;DANIELS.BONES&quot; is an undefined name.  SQLSTATE=42704
)
</pre></div>
    </div>
   </div>
  </p>

 </div>


 <div class="refsect1 seealso" id="refsect1-pdostatement.errorinfo-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pdo.errorcode.html" class="function" rel="rdfs-seeAlso">PDO::errorCode()</a> - 获取跟数据库句柄上一次操作相关的 SQLSTATE</span></li>
    <li class="member"><span class="function"><a href="pdo.errorinfo.html" class="function" rel="rdfs-seeAlso">PDO::errorInfo()</a> - Fetch extended error information associated with the last operation on the database handle</span></li>
    <li class="member"><span class="function"><a href="pdostatement.errorcode.html" class="function" rel="rdfs-seeAlso">PDOStatement::errorCode()</a> - 获取跟上一次语句句柄操作相关的 SQLSTATE</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>